package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-08-29
 * Time: 20:56
 */
class Counter1{
    public int count = 0;
    public void add(){
        count++;
    }
}
public class ThreadD13 {

    public static void main(String[] args) {

        Counter1 counter1 = new Counter1();
        Thread t1 = new Thread(() ->{
            for (int i = 0; i < 10000; i++) {
                counter1.add();
            }
        });
        Thread t2 = new Thread(() ->{
            for (int i = 0; i < 10000; i++) {
                counter1.add();
            }
        });
      t1.start();
      t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
           e.printStackTrace();
        }
        System.out.println(counter1.count);
    }
}
